<template>
  <div class="app-container">
    <el-container class="full-height">
      <el-aside width="220px" class="sidebar">
        <el-menu
          router
          :default-active="$route.path"
          class="el-menu-vertical"
          background-color="#545c64"
          text-color="#fff"
          active-text-color="#ffd04b"
        >
          <el-menu-item index="/">
            <el-icon><el-icon-document /></el-icon>
            <span>文档浏览</span>
          </el-menu-item>
          <el-menu-item index="/subscriptions">
            <el-icon><el-icon-star /></el-icon>
            <span>我的订阅</span>
          </el-menu-item>
          <el-menu-item index="/notifications">
            <el-icon><el-icon-bell /></el-icon>
            <span>通知中心</span>
          </el-menu-item>
          <el-menu-item index="/manage">
            <el-icon><el-icon-setting /></el-icon>
            <span>文档管理</span>
          </el-menu-item>
          <el-menu-item index="/admin">
            <el-icon><el-icon-user /></el-icon>
            <span>后台管理</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <el-container class="main-content">
        <el-header style="text-align: right; font-size: 12px">
          <el-dropdown>
            <span class="el-dropdown-link">
              {{ userStore.username || '用户' }}
              <el-icon class="el-icon--right"><arrow-down /></el-icon>
            </span>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item>个人中心</el-dropdown-item>
                <el-dropdown-item @click="logout">退出登录</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
        </el-header>
        <el-main class="content-area">
          <router-view />
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script setup>
import { useRouter } from 'vue-router'
import { useUserStore } from './stores/user'
import { ArrowDown } from '@element-plus/icons-vue'

const router = useRouter()
const userStore = useUserStore()

const logout = () => {
  userStore.logout()
  router.push('/login')
}
</script>

<style>
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  overflow: hidden;
}

.app-container {
  height: 100vh;
  width: 100vw;
  display: flex;
  flex-direction: column;
}

.full-height {
  height: 100%;
}

.sidebar {
  height: 100vh;
}

.main-content {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.content-area {
  flex: 1;
  overflow-y: auto;
}

.el-header {
  background-color: #b3c0d1;
  color: #333;
  line-height: 60px;
  padding: 0 20px;
}

.el-aside {
  color: #333;
}

.el-menu-vertical {
  height: 100%;
  border-right: none;
}

.el-dropdown-link {
  cursor: pointer;
  color: #409eff;
}

.el-main {
  padding: 20px;
}
</style> 